<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition>
        <p:dialog id="dlg_fcbnew" header="#{msg.classroom_dialog_fcbNewDialog_header}" widgetVar="fcbNewDialog" modal="true">
            <p:ajax event="close" update=":frm_fcb" listener="#{fileCardBoxBean.cancel}" oncomplete="fcbNewDialog.hide()" immediate="true"/>
            <h:form>
                <p:panel id="opp_dcbnd">
                    <p:panelGrid styleClass="noborder" columns="3">
                        <p:outputLabel id="lbl_title" for="txt_title" value="#{msg.classroom_dialog_fcbNewDialog_lbl_title_value}"/>
                        <p:inputText id="txt_title" value="#{fileCardBoxBean.fcb.title}" required="true" 
                                     requiredMessage="#{msg.classroom_dialog_fcbNewDialog_txt_desc_reqMes}"/>
                        <p:message for="txt_title" showDetail="true"/>
                        <p:outputLabel id="lbl_desc" for="txt_desc" value="#{msg.classroom_dialog_fcbNewDialog_lbl_desc_value}"/>
                        <p:inputText id="txt_desc" value="#{fileCardBoxBean.fcb.description}" required="true" 
                                     requiredMessage="#{msg.classroom_dialog_fcbNewDialog_txt_desc_reqMes}"/>
                        <p:message for="txt_desc" showDetail="true"/>
                        <p:outputLabel id="lbl_cat1" for="som_cat1" value="#{msg.classroom_dialog_fcbNewDialog_lbl_cat1_value}"/>
                        <p:selectOneMenu id="som_cat1" value="#{fileCardBoxBean.cat1}" converter="#{CategoryConverter}" 
                                         required="true" requiredMessage="#{msg.classroom_dialog_fcbNewDialog_som_cat1_reqMes}">
                            <f:selectItem itemLabel="#{msg.som_lbl_choose}" itemValue=""/>
                            <f:selectItems value="#{fileCardBoxBean.allCategories}" var="cat1" itemLabel="#{cat1.name}" itemValue="#{cat1}" itemDescription="#{cat1.description}"/>
                            <p:ajax update="som_cat2, som_cat3"/>
                        </p:selectOneMenu>
                        <p:message id="msg_cat1" for="som_cat1" showDetail="true"/>
                        <p:outputLabel id="lbl_cat2" for="som_cat2" value="#{msg.classroom_dialog_fcbNewDialog_lbl_cat2_value}"/>
                        <p:selectOneMenu id="som_cat2" value="#{fileCardBoxBean.cat2}" converter="#{CategoryConverter}" 
                                         disabled="#{(fileCardBoxBean.cat1 == null) or (fileCardBoxBean.cat1.underCategories.size() == 0)}">
                            <f:selectItem itemLabel="#{msg.som_lbl_choose}" itemValue=""/>
                            <f:selectItems value="#{fileCardBoxBean.cat1.underCategories}" var="cat2" itemLabel="#{cat2.name}" itemValue="#{cat2}" itemDescription="#{cat2.description}"/>
                            <p:ajax update="som_cat2, som_cat3"/>
                        </p:selectOneMenu>
                        <p:message id="msg_cat2" for="som_cat3" showDetail="true"/>
                        <p:outputLabel id="lbl_cat3" for="som_cat3" value="#{msg.classroom_dialog_fcbNewDialog_lbl_cat3_value}"/>
                        <p:selectOneMenu id="som_cat3" value="#{fileCardBoxBean.cat3}" converter="#{CategoryConverter}" 
                                         disabled="#{(fileCardBoxBean.cat2 == null) or (fileCardBoxBean.cat2.underCategories.size() == 0)}">
                            <f:selectItem itemLabel="#{msg.som_lbl_choose}" itemValue=""/>
                            <f:selectItems value="#{fileCardBoxBean.cat2.underCategories}" var="cat3" itemLabel="#{cat3.name}" itemValue="#{cat3}" itemDescription="#{cat3.description}"/>
                        </p:selectOneMenu>
                        <p:message id="msg_cat3" for="som_cat3" showDetail="true"/>
                    </p:panelGrid>
                    <f:facet name="footer">
                        <p:commandButton id="btn_save" value="#{msg.btn_save}" actionListener="#{fileCardBoxBean.save}" oncomplete="handleSaveRequest(xhr, status, args)" update=":frm_fcb"/>
                        <p:commandButton id="btn_cancel" value="#{msg.btn_cancel}" actionListener="#{fileCardBoxBean.cancel}" oncomplete="fcbNewDialog.hide()" update=":dlg_fcbnew" process="@this"/>
                    </f:facet>
                </p:panel>
            </h:form>
        </p:dialog>
        <script type="text/javascript">  
            function handleSaveRequest(xhr, status, args) {  
                if(args.validationFailed) {  
                    jQuery('#dlg_fcbnew').effect("shake", { times:3 }, 100);  
                } else {  
                    fcbNewDialog.hide();  
                    jQuery('#btn_new').fadeOut();  
                }  
            }  
        </script> 
    </ui:composition>
</html>

